<%@ page import="com.apexedu.identity.entity.TSysUser" %>
<%@ page import="com.apexedu.identity.IdConstants" %>
<%@ page import="com.apexedu.identity.security.CasLoginUtil" %>
<%@ page import="com.apexedu.framework.util.SysPropertiesUtil" %>
<%@ page import="com.apexedu.util.StringUtil" %>
<%@ page import="com.apexedu.portal.entity.TMessage" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    request.setAttribute("basePath", request.getContextPath());
    TSysUser user = (TSysUser) request.getSession().getAttribute(IdConstants.SESSION_USER);
    if (null != user) {
        request.setAttribute("userid", user.getUserloginid());
        request.setAttribute("username", user.getUsername());
    }
    String messagenum = (String) request.getAttribute("messagenum") != null ? (String) request.getAttribute("messagenum") : "";
%>
<style>
    #head .label, .badge {
        background-color: #999;
        color: #fff;
        font-size: 11.844px;
        font-weight: bold;
        line-height: 14px;
        padding: 2px 4px;
        text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
        vertical-align: baseline;
        white-space: nowrap;
    }

    #head .badge {
        border-radius: 9px;
        padding-left: 7px;
        padding-right: 7px;
    }

    .label-important, .badge-important {
        background-color: #b94a48;
    }

    .moreDiv {
        position: relative;
        right: -30px;
        top: 3px;
        letter-spacing: 6px;
        font-size: 8px;
        cursor: pointer;
    }
</style>
<script type="text/javascript">
    var basePath = '${basePath}';
    function execLogout() {
        <%
        if( CasLoginUtil.isSsoEnabled() ){
          // 通知业务系统liveBos登出。
          // 这里的地址是根据项目现场业务系统地址在门户管理后台的系统参数维护里修改。参数名用“livebos.urls”
            String liveBosUrl = SysPropertiesUtil.get("livebos.urls");
            if(StringUtil.isNotBlank(liveBosUrl)){
                String[] liveBosUrls = liveBosUrl.split(",");
                for(String url : liveBosUrls){
                    out.println("$(\"<iframe src='"+url+"/logout.do' height='0' frameborder='0'/>\").appendTo(\"body\");");
                }
            }
        }
        %>
        $.get("${basePath}/identity/ajaxlogin.action?act=logout", {q: (new Date()).getTime()}, function (data) {
            data = eval("(" + data + ")");
            if (data.msg == 'success') {
                <%
            if( CasLoginUtil.isSsoEnabled() ){
            %>
                window.location.href = '<%=CasLoginUtil.getCasServerLogoutUrl()%>?t=' + Math.round(new Date / 1000);
                <%
                }else{
                %>
                window.location.href = '<%=request.getContextPath() %>?t=' + Math.round(new Date / 1000);
                <%
                }
                %>
            } else {
                alert(data.msg);
            }
        });

    }

    function chanehtml(url) {
        location.target = "_blank";
        location.href = url;
    }

    function gotoHtml(url) {
        window.open('${basePath}/s/uc/yw/index?url=' + url);
    }

    function readMessage(messagewid, url, obj) {
        if (url == "") {
            layer.open({
                type: 2,
                title: '消息详情',
                shadeClose: true,
                shade: 0.8,
                area: ['600px', '450px'],
                content: '/s/m/detail/' + messagewid
            });
        } else {
            $.post("/s/m/read/" + messagewid, function (result) {
                window.open('${basePath}/s/uc/yw/index?url=' + url);
            });
        }

    }
</script>
<div class="notice">
    <div class="notice1">
        <span class="notice2">消息提醒</span>
        <span id="close" title="关闭">X</span>
    </div>
    <c:if test="${null != ls_oa && ls_oa.size() > 0}">
        <div class="notice_tx">
            <div class="notice_title">
                <label>OA办公未读消息</label>
                <span class="moreDiv" onclick="window.location.href='${basePath}/s/m/index'" title="更多">●●●</span>
            </div>
            <div class="notice3">
                <c:forEach items="${ls_oa}" var="item">
                    <li class="oa" onclick="readMessage('${item.wid}','${item.url}',this)"><span><a>${item.bt}</a></span></li>
                </c:forEach>
            </div>
        </div>
    </c:if>
    <c:if test="${ls_hr.size() > 0}">
        <div class="notice_tx">
            <div class="notice_title">
                <label>人事未读消息</label>
                <span class="moreDiv" onclick="window.location.href='${basePath}/s/m/index'" title="更多">●●●</span>
            </div>
            <div class="notice3">
                <c:forEach items="${ls_hr}" var="item">
                    <li class="hr" onclick="readMessage('${item.wid}','${item.url}',this)"><span><a>${item.bt}</a></span></li>
                </c:forEach>
            </div>
        </div>
    </c:if>
</div>
<div id="head">
    <div class="logo" onclick="window.location.href='${basePath}/'">&nbsp;</div>
    <label style="height:60px;line-height:60px;">网上办事大厅</label>
    <div class="info">
        ${username}<img alt="用户头像" src="${basePath}/userinfo/${userid}"
                        style="width: 34px; height: 34px;margin-left: 10px;"
                        onerror="this.src='${basePath}/userinfo/user_male_portrait.png'">
        <span class="mask"></span>
        <div class="headMenu">
            <ul>
                <%if ("admin".equals(user.getUserloginid())) {%>
                <li onclick="window.location.href='${basePath}/identity/index.action?flag=true'">
                    <div class="htgl">管理后台</div>
                </li>
                <%}%>
                <li onclick="window.open('${basePath}/s/uc/mh/up')">
                    <div class="mmxg">密码修改</div>
                </li>
                <li onclick="window.open('${basePath}/s/uc/mh/hp')">
                    <div class="txsw">信息维护</div>
                </li>
                <li class="zx" onclick="execLogout()">
                    <div>注&nbsp;&nbsp;销</div>
                </li>
            </ul>
        </div>
    </div>
    <%if ("admin".equals(user.getUserloginid())) {%>
    <div class="role" style="width: 120px;">站点切换
        <div class="headMenuRole">
            <ul>
                <li onclick="gotohtml('${basePath}/s/uc/index/student');">
                    <div class="txsw">学生服务</div>
                </li>
                <li onclick="gotohtml('${basePath}/s/uc/index/teacher');">
                    <div class="txsw">教师服务</div>
                </li>
                <li onclick="gotohtml('${basePath}/s/uc/index/leader');">
                    <div class="txsw">领导服务</div>
                </li>
            </ul>
        </div>
    </div>
    <%}%>
    <div class="more" style="width: 100px;height: 60px;line-height: 60px;">
        <img alt="消息" src="${basePath}/resources/images/shd/icon_m.png" style="width: 18px;height: 18px;margin-left: 10px;display: inline-block;position: absolute;right: 0;top: 13px;z-index: 11;">
        <span style="color: red;height: 60px;line-height: 60px;position: absolute; right: -17px;top: -7px;" onclick="window.location.href='${basePath}/s/m/index'"><%=messagenum%></span>
        <div id="unreadMessage">
        </div>
    </div>
    <%--显示未读信息--%>
    <jsp:include page="message/unread.jsp"/>
</div>